package logic

import (
	"context"

	"user/api/internal/svc"
	"user/api/internal/types"
	__ "user/pb"

	"github.com/zeromicro/go-zero/core/logx"
)

type GetuserLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewGetuserLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetuserLogic {
	return &GetuserLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *GetuserLogic) Getuser(req *types.UserReq) (resp *types.UserResp, err error) {
	// todo: add your logic here and delete this line
	grpcRsp, grpcErr := l.svcCtx.UserClient.GetUserInfo(l.ctx, &__.GetUserReq{
		Id: req.Id,
	})
	if grpcErr != nil {
		return nil, grpcErr
	}
	return &types.UserResp{
		Id:    grpcRsp.Id,
		Name:  grpcRsp.Name,
		Phone: grpcRsp.Phone,
	}, nil
}
